﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="vote.aspx.cs" Inherits="skvote.vote1" ValidateRequest="false"%>

<%@ Import Namespace="System.Data.OleDb"%>
<%@ Import Namespace="System.Data" %>

<%
    string sid = Request["sid"];
    
     Response.Write("你好啊rr4 ");
    
    if (string.IsNullOrEmpty(sid))
    {
        Response.Write(" <div align='center'><font color='red'>主题参数sid不能为空</font></div>");
        Response.End();
        Response.Write("你好啊");
    }
    try
    {
        Convert.ToInt32(sid);
    }
    catch(Exception)
    {
        Response.Write("document.write(\"<div align='center'><font color='red'>主题参数sid只能是数字</font></div>\");");
        Response.End();
    }
    OleDbConnection sconn = new skvote.conn().CreateConnection();
    System.TimeSpan ts = new TimeSpan();
    bool subjectExist = true;
    try
    {
        OleDbCommand scmd = new OleDbCommand("select qx from xh_subject where id=" + sid, sconn);
        OleDbDataReader sdr = scmd.ExecuteReader();
        if (sdr.Read())
        {
            ts = sdr.GetDateTime(0).Subtract(DateTime.Now);            
        }
        else
        {
            subjectExist = false;
        }
        
    }
    finally
    {
        sconn.Close();
    }
    if (!subjectExist)
    {
        Response.Write("document.write(\"<div align='center'><font color='red'>该主题不存在或已被删除</font></div>\");");
        Response.End();
    }
    if (ts != null)
    {
        if (ts.Days > 0)
        {
            Response.Write("document.write(\"<div align='center'><font color='red'>该主题已经过期</font></div>\");");
            Response.End();
        }
    }

    skvote.config cfg = new skvote.config();
    bool getUserInfo = cfg.getUserInfo(), allowView = cfg.getAllowView();
    string weburl = cfg.getWebName(), webname = cfg.getWebName();
    if (getUserInfo)
    {
        Response.Write("document.write(\"<\");");
        Response.Write("document.write(\"script language='javascript' type='text/javascript'>\");\r\n");
        Response.Write("document.write(\"function checkVote()\");\r\n");
        Response.Write("document.write(\"{  var skvote = document.frmskvote;\");\r\n");
        Response.Write("document.write(\"  if (skvote.name.value=='')\");\r\n"); 
        Response.Write("document.write(\"  {   document.getElementById('lblname').innerHTML='<font color=red>姓名不能为空</font>';\");\r\n");
        Response.Write("document.write(\"      skvote.name.focus();\");\r\n");
        Response.Write("document.write(\"      return false;\");\r\n");
        Response.Write("document.write(\"  }else\");\r\n");
        Response.Write("document.write(\"  {\");\r\n");
        Response.Write("document.write(\"      document.getElementById('lblname').innerHTML='';\");\r\n");
        Response.Write("document.write(\"  }\");\r\n");
        Response.Write("document.write(\"  if (skvote.idcard.value=='')\");\r\n");
        Response.Write("document.write(\"  {   document.getElementById('lblidcard').innerHTML='<font color=red>身份证号码不能为空</font>';\");\r\n");
        Response.Write("document.write(\"      skvote.idcard.focus();\");\r\n");
        Response.Write("document.write(\"      return false;\");\r\n");
        Response.Write("document.write(\"   }else\");\r\n");
        Response.Write("document.write(\"   {\");\r\n");
        Response.Write("document.write(\"      document.getElementById('lblidcard').innerHTML='';\");\r\n");
        Response.Write("document.write(\"   }\");\r\n");
        Response.Write("document.write(\"   if (skvote.email.value=='')\");\r\n");
        Response.Write("document.write(\"   {  \");\r\n");
        Response.Write("document.write(\"      document.getElementById('lblemail').innerHTML='<font color=red>邮箱地址不能为空</font>';\");\r\n");
        Response.Write("document.write(\"      skvote.email.focus();\");\r\n");
        Response.Write("document.write(\"      return false;\");\r\n");
        Response.Write("document.write(\"   }else\");\r\n");
        Response.Write("document.write(\"   {\");\r\n");
        Response.Write("document.write(\"      document.getElementById('lblemail').innerHTML='';\");\r\n");
        Response.Write("document.write(\"   }\");\r\n");
        Response.Write("document.write(\"}\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/script>\");\r\n");
    }

    string systemurl = cfg.getSystemUrl();
    if (getUserInfo)
    {
        Response.Write("document.write(\"<\");\r\n");
        //Response.Write("document.write(\"form action='view.aspx?sid="+sid+"' method='post' name='frmskvote' id='frmskvote' target='_blank' onsubmit='return checkVote()'>\");\r\n"); //only test
        Response.Write("document.write(\"form action='"+systemurl+"view.aspx?sid=" + sid + "' method='post' name='frmskvote' id='frmskvote' target='_blank' onsubmit='return checkVote()'>\");\r\n");
    }
    else
    {
        Response.Write("document.write(\"<\");\r\n");
        //Response.Write("document.write(\"form action='view.aspx?sid="+sid+"' method='post' name='frmskvote' id='frmskvote' target='_blank'>\");\r\n");//only test
        Response.Write("document.write(\"form action='"+systemurl+"view.aspx?sid=" + sid + "' method='post' name='frmskvote' id='frmskvote' target='_blank'>\");\r\n");
    }

    OleDbConnection tconn = new skvote.conn().CreateConnection();
    try
    {
        OleDbDataAdapter tda = new OleDbDataAdapter("select * from xh_title where sid=" + sid, tconn);
        DataSet tds = new DataSet();
        tda.Fill(tds, "title");
        foreach (DataRow dr in tds.Tables["title"].Rows)
        {
            Response.Write("document.write(\"<\");\r\n");
            Response.Write("document.write(\"div align='left'>\");\r\n");
            Response.Write("document.write(\"<\");\r\n");
            Response.Write("document.write(\"table border='0' cellspacing='1' cellpadding='3'>\");\r\n");
            Response.Write("document.write(\"<\");\r\n");
            Response.Write("document.write(\"tr>\");\r\n");
            Response.Write("document.write(\"<\");\r\n");
            Response.Write("document.write(\"td nowrap colspan='" + dr["listrows"].ToString() + "'>\");\r\n");
            Response.Write("document.write(\""+dr["title"].ToString()+"\");\r\n");
            Response.Write("document.write(\"<\");\r\n");
            Response.Write("document.write(\"/td>\");\r\n");
            Response.Write("document.write(\"<\");\r\n");
            Response.Write("document.write(\"/tr>\");\r\n");
            OleDbConnection qconn = new skvote.conn().CreateConnection();
            OleDbDataAdapter qda = new OleDbDataAdapter("select * from xh_question where tid=" + dr["id"].ToString(), qconn);
            DataSet qds = new DataSet();
            qda.Fill(qds, "question");
            int i = 0, rows = qds.Tables["question"].Rows.Count - 1;
            foreach (DataRow qdr in qds.Tables["question"].Rows)
            {
                
                if (i % Convert.ToInt32(dr["listrows"]) == 0)
                {
                    if (i == 0)
                    {
                        Response.Write("document.write(\"<\");\r\n");
                        Response.Write("document.write(\"tr>\");\r\n");
                    }
                    else
                    {
                        Response.Write("document.write(\"<\");\r\n");
                        Response.Write("document.write(\"/tr>\");\r\n");
                        Response.Write("document.write(\"<\");\r\n");
                        Response.Write("document.write(\"tr>\");\r\n");
                    }
                }
                Response.Write("document.write(\"<\");\r\n");
                Response.Write("document.write(\"td>\");\r\n");
                if (Convert.ToInt32(dr["ms"]) == 1)//单选
                {
                    if (Convert.ToInt32(dr["listtype"]) == 0)//文字列表
                    {
                        Response.Write("document.write(\"<\");\r\n");
                        Response.Write("document.write(\"input type='radio' name='" + dr["id"].ToString() + "' value='" + qdr["id"].ToString() + "'/>\");\r\n");
                        Response.Write("document.write(\"" + qdr["question"].ToString() + "\");\r\n");
                    }
                    else if(Convert.ToInt32(dr["listtype"])==1)//图片列表
                    {
                        Response.Write("document.write(\"<\");\r\n");
                        Response.Write("document.write(\"input type='radio' name='" + dr["id"].ToString() + "' value='" + qdr["id"].ToString() + "'/>\");\r\n");
                        Response.Write("document.write(\"<\")'\r\n");
                        Response.Write("document.write(\"img src='" + qdr["imgurl"].ToString() + "' alt='" + qdr["question"].ToString() + "'/>\");\r\n");
                    }
                }
                else if (Convert.ToInt32(dr["ms"]) == 2)//多选
                {
                    if (Convert.ToInt32(dr["listtype"]) == 0) //文字列表
                    {
                        Response.Write("document.write(\"<\");\r\n");
                        Response.Write("document.write(\"input type='checkbox' name='" + dr["id"].ToString() + "' value='" + qdr["id"].ToString() + "'/>\");\r\n");
                        Response.Write("document.write(\""+qdr["question"].ToString()+"\");\r\n");
                    }
                    else if (Convert.ToInt32(dr["listtype"]) == 1)//图片列表
                    {
                        Response.Write("document.write(\"<\");\r\n");
                        Response.Write("document.write(\"input type='checkbox' name='" + dr["id"].ToString() + "' value='" + qdr["id"].ToString() + "'/>\");\r\n");
                        Response.Write("document.write(\"<\");\r\n");
                        Response.Write("document.write(\"img src='" + qdr["imgurl"].ToString() + "' alt='" + qdr["question"].ToString() + "'/>\");\r\n");
                    }                        
                }
                Response.Write("document.write(\"<\");\r\n");
                Response.Write("document.write(\"/td>\");\r\n");
                if (i == rows)
                {
                    for (int j = (i%Convert.ToInt32(dr["listrows"])); j < (Convert.ToInt32(dr["listrows"])-1); j++)
                    {
                        Response.Write("document.write(\"<\");\r\n");
                        Response.Write("document.write(\"td>"+j.ToString()+"\");\r\n");
                        Response.Write("document.write(\"<\");\r\n");
                        Response.Write("document.write(\"/td>\");\r\n");                        
                    }
                    Response.Write("document.write(\"<\");\r\n");
                    Response.Write("document.write(\"/tr>\");\r\n");
                }
                i++;                                
            }
            qconn.Close();
            Response.Write("document.write(\"<\");\r\n");
            Response.Write("document.write(\"/table>\");\r\n");
            Response.Write("document.write(\"<\");\r\n");
            Response.Write("document.write(\"/div>\");\r\n");
        }
    }
    finally
    {
        tconn.Close();
    }

    if (getUserInfo)
    {
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"table border='0' width='200' cellspacing='1' cellpadding='3'>\");\r\n");
        
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"tr>\");\r\n");
        
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>姓名:\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"input type='text' name='name' id='name' size='30'/>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"label id='lblname'>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/label>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");
        
        Response.Write("document.write(\"</\");\r\n");
        Response.Write("document.write(\"tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>性别:\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"select id='sex' name='sex'>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"option value='男'>男\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/option>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"option value='女'>女\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/option>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/select>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>身份证号码:\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"input type='text' id='idcard' name='idcard' size='30'/>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"label id='lblidcard'>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/label>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>电话:\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"input type='text' id='tel' name='tel' size='30'/>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");
                
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>地址:\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"input type='text' id='address' name='address' size='30'/>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>邮箱:\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"input type='text' id='email' name='email' size='30'/>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"label id='lblemail'>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/label>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"tr>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>备注:\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"td>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"textarea cols='25' rows='3' name='remarks' id='remarks'>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/textarea>\");\r\n");
        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/td>\");\r\n");

        Response.Write("document.write(\"<\");\r\n");
        Response.Write("document.write(\"/tr>\");\r\n");
        
    }


    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"table border='0' width='200' cellpadding='3' cellspacing='1'>\");\r\n");
    
    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"tr>\");\r\n");

    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"td>\");\r\n");

    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"input type='submit' name='submit' id='submit' value='投票'/>&nbsp;\");\r\n");
    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"input type='button' name='submit' id='submit' value='查看' onclick=javascript:window.open('view.aspx?sid=" + sid + "'); />\");\r\n");
    //Response.Write("document.write(\"input type='button' name='submit' id='submit' value='查看' onclick=javascript:window.open('view.apsx?sid=" + sid + "');/>\");\r\n");
    
    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"/td>\");\r\n");
    
    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"/tr>\");\r\n");

    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"tr>\");\r\n");
    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"td nowrap>\");\r\n");
    Response.Write("document.write(\"Powered By : skvote(asp.net) v3.0.1106<br/>CopyRight 2004-2008 &copy\");\r\n");
    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"a href='" + weburl + "' target='_blank'>\");\r\n");
    Response.Write("document.write(\"" +webname + "\");\r\n");
    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"/a>\");\r\n");
    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"/td>\");\r\n");
    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"/tr>\");\r\n");
    
    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"/table>\");\r\n");

    Response.Write("document.write(\"<\");\r\n");
    Response.Write("document.write(\"/form>\");\r\n");
%>
